package com.softcloud.comingforyuan.activity;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import com.softcloud.comingforyuan.R;
import com.softcloud.comingforyuan.model.ActivityCollector;
import com.softcloud.comingforyuan.model.BaseActivity;

import java.util.Calendar;

public class KnowledgeActivity extends BaseActivity {

    private int lastHour;
    private int lastMin;
    private int lastSec;

    private TextView titleText;
    private TextView contentText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_knowledge);

        titleText = (TextView)findViewById(R.id.title_text);
        titleText.setText("知识点学习");

        contentText = (TextView)findViewById(R.id.knowledge_content);
        contentText.setText(R.string.knowledge);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_knowledge, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        Calendar calendar = Calendar.getInstance();
        int currHour = calendar.get(Calendar.HOUR);
        int currMin = calendar.get(Calendar.MINUTE);
        int currSec = calendar.get(Calendar.SECOND);
        if(currHour == lastHour && currMin == lastMin && currSec-lastSec<=2){
            ActivityCollector.finishAll();
        }else{
            lastHour = currHour;
            lastMin = currMin;
            lastSec = currSec;
            Toast.makeText(this, "再次点击退出程序", Toast.LENGTH_SHORT).show();
        }
    }
}
